package main

import (
	"fmt"
)

func main() {
	arr := []int{2, 2, 3}
	fmt.Println(maxLength(arr))

}

func maxLength(arr []int) int {

	// write code here
	valueIndexMap := make(map[int]int)
	maxLen := 0
	start := 0
	for i, v := range arr {
		if _, ok := valueIndexMap[v]; ok {
			start = MaxInt(start, valueIndexMap[v]+1)
		}
		valueIndexMap[v] = i
		maxLen = MaxInt(maxLen, i-start+1)
	}
	return maxLen

}
func MaxInt(a, b int) int {
	if a > b {
		return a
	}
	return b
}
